<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入理解G1垃圾回收器 | 技术小馆</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
            background-color: #f9fafb;
        }
        .serif {
            font-family: 'Noto Serif SC', serif;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
        }
        .drop-cap:first-letter {
            float: left;
            font-size: 4.5rem;
            line-height: 0.65;
            margin: 0.15em 0.1em 0 0;
            color: #4c51bf;
            font-weight: bold;
        }
        .timeline-item::before {
            content: "";
            position: absolute;
            left: -1.5rem;
            top: 0;
            width: 0.5rem;
            height: 100%;
            background-color: #4c51bf;
            border-radius: 0.25rem;
        }
        .mermaid {
            background-color: white;
            border-radius: 0.5rem;
            padding: 1.5rem;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl text-center">
            <div class="flex justify-center mb-6">
                <span class="px-4 py-1 bg-white bg-opacity-20 rounded-full text-sm font-medium">JVM 系列</span>
            </div>
            <h1 class="serif text-4xl md:text-5xl font-bold leading-tight mb-6">深入理解G1垃圾回收器</h1>
            <p class="text-xl md:text-2xl text-white text-opacity-90 max-w-3xl mx-auto">
                Java大堆内存应用的性能优化利器 - 平衡效率与停顿时间的艺术
            </p>
            <div class="mt-10 flex justify-center space-x-4">
                <a href="#overview" class="px-6 py-3 bg-white text-indigo-700 font-medium rounded-lg hover:bg-opacity-90 transition duration-300 flex items-center">
                    <i class="fas fa-book-open mr-2"></i> 核心概念
                </a>
                <a href="#process" class="px-6 py-3 bg-white bg-opacity-10 border border-white border-opacity-30 text-white font-medium rounded-lg hover:bg-opacity-20 transition duration-300 flex items-center">
                    <i class="fas fa-project-diagram mr-2"></i> 工作原理
                </a>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 py-12 md:py-16">
        <!-- Overview Section -->
        <section id="overview" class="mb-16">
            <h2 class="serif text-3xl font-bold mb-8 text-gray-800 border-b pb-4 flex items-center">
                <i class="fas fa-bullseye mr-3 text-indigo-600"></i> G1垃圾回收器的核心目标
            </h2>
            
            <div class="grid md:grid-cols-3 gap-6 mb-12">
                <!-- Card 1 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 bg-indigo-100 p-3 rounded-lg">
                                <i class="fas fa-stopwatch text-indigo-600 text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg font-semibold text-gray-800">低停顿时间</h3>
                        </div>
                        <p class="text-gray-600">
                            G1的主要目标是将垃圾回收的停顿时间控制在用户设定的目标范围内，适用于对延迟敏感的应用场景。
                        </p>
                    </div>
                </div>
                
                <!-- Card 2 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 bg-purple-100 p-3 rounded-lg">
                                <i class="fas fa-tachometer-alt text-purple-600 text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg font-semibold text-gray-800">高回收效率</h3>
                        </div>
                        <p class="text-gray-600">
                            通过优先回收垃圾最多的区域(Region-based)，提高垃圾回收的效率，最大化释放内存空间。
                        </p>
                    </div>
                </div>
                
                <!-- Card 3 -->
                <div class="bg-white rounded-xl shadow-md overflow-hidden card-hover">
                    <div class="p-6">
                        <div class="flex items-center mb-4">
                            <div class="flex-shrink-0 bg-blue-100 p-3 rounded-lg">
                                <i class="fas fa-memory text-blue-600 text-xl"></i>
                            </div>
                            <h3 class="ml-4 text-lg font-semibold text-gray-800">大堆内存支持</h3>
                        </div>
                        <p class="text-gray-600">
                            专为处理大堆内存设计，能够有效管理TB级别的堆内存，适合现代企业级应用需求。
                        </p>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover">
                <div class="p-8">
                    <div class="flex items-start">
                        <div class="flex-shrink-0 bg-yellow-100 p-4 rounded-lg">
                            <i class="fas fa-lightbulb text-yellow-600 text-2xl"></i>
                        </div>
                        <div class="ml-6">
                            <h3 class="text-xl font-semibold text-gray-800 mb-3">为什么需要G1垃圾回收器？</h3>
                            <p class="text-gray-600">
                                随着Java应用堆内存的不断扩大，传统的垃圾回收器(CMS、Parallel等)在处理大堆内存时面临诸多挑战：停顿时间长、内存碎片化等问题日益突出。G1(垃圾优先)回收器应运而生，它通过创新的区域化内存布局和基于停顿预测模型的回收策略，在保证吞吐量的同时，显著降低了垃圾回收的停顿时间。
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- Process Section -->
        <section id="process" class="mb-16">
            <h2 class="serif text-3xl font-bold mb-8 text-gray-800 border-b pb-4 flex items-center">
                <i class="fas fa-cogs mr-3 text-indigo-600"></i> G1垃圾回收流程详解
            </h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 mb-12 card-hover">
                <h3 class="text-2xl font-semibold mb-6 text-gray-800 flex items-center">
                    <i class="fas fa-sitemap mr-3 text-indigo-500"></i> 堆内存结构
                </h3>
                <div class="grid md:grid-cols-2 gap-8 items-center">
                    <div>
                        <p class="text-gray-600 mb-4">
                            G1将堆内存划分为多个大小相等的区域(Region)，每个Region可以是年轻代(Eden、Survivor)或老年代。这种设计避免了传统分代模型中各代空间必须连续的限制，提供了更大的灵活性。
                        </p>
                        <ul class="list-disc pl-5 text-gray-600 space-y-2">
                            <li>Region大小可通过<code class="bg-gray-100 px-2 py-1 rounded">-XX:G1HeapRegionSize</code>设置(1MB-32MB)</li>
                            <li>年轻代占比可通过<code class="bg-gray-100 px-2 py-1 rounded">-XX:G1NewSizePercent</code>和<code class="bg-gray-100 px-2 py-1 rounded">-XX:G1MaxNewSizePercent</code>调节</li>
                            <li>老年代不再是一个连续空间，而是由多个Region组成</li>
                        </ul>
                    </div>
                    <div class="mermaid">
                        graph LR
                            A[G1 Heap] --> B[Region 1: Eden]
                            A --> C[Region 2: Survivor]
                            A --> D[Region 3: Old]
                            A --> E[Region 4: Eden]
                            A --> F[Region 5: Old]
                            A --> G[Region 6: Humongous]
                            style A fill:#f5f5f5,stroke:#4c51bf,stroke-width:2px
                            style B fill:#93c5fd,stroke:#1e40af
                            style C fill:#a5b4fc,stroke:#4338ca
                            style D fill:#fca5a5,stroke:#b91c1c
                            style E fill:#93c5fd,stroke:#1e40af
                            style F fill:#fca5a5,stroke:#b91c1c
                            style G fill:#d8b4fe,stroke:#7e22ce
                    </div>
                </div>
            </div>
            
            <h3 class="text-2xl font-semibold mb-6 text-gray-800 flex items-center">
                <i class="fas fa-project-diagram mr-3 text-indigo-500"></i> 垃圾回收阶段
            </h3>
            
            <div class="relative pl-8 mb-12">
                <div class="absolute left-0 top-0 h-full w-0.5 bg-gradient-to-b from-indigo-400 to-purple-500"></div>
                
                <!-- Phase 1 -->
                <div class="relative mb-10 timeline-item">
                    <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                        <div class="flex items-center mb-3">
                            <span class="flex items-center justify-center w-10 h-10 rounded-full bg-indigo-100 text-indigo-700 font-bold mr-4">1</span>
                            <h4 class="text-xl font-semibold text-gray-800">初始标记 (Initial Mark)</h4>
                            <span class="ml-auto px-3 py-1 bg-red-100 text-red-800 text-sm font-medium rounded-full">STW</span>
                        </div>
                        <p class="text-gray-600 pl-14">
                            标记从GC Root直接可达的对象，需要短暂暂停应用线程(STW)。此阶段通常与年轻代回收一起完成，利用"Snapshot-At-The-Beginning"(SATB)算法记录初始标记点。
                        </p>
                    </div>
                </div>
                
                <!-- Phase 2 -->
                <div class="relative mb-10 timeline-item">
                    <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                        <div class="flex items-center mb-3">
                            <span class="flex items-center justify-center w-10 h-10 rounded-full bg-blue-100 text-blue-700 font-bold mr-4">2</span>
                            <h4 class="text-xl font-semibold text-gray-800">并发标记 (Concurrent Mark)</h4>
                            <span class="ml-auto px-3 py-1 bg-green-100 text-green-800 text-sm font-medium rounded-full">并发</span>
                        </div>
                        <p class="text-gray-600 pl-14">
                            扫描整个堆，标记所有从初始标记阶段开始可达的对象。此阶段与应用线程并发执行，不会暂停应用。G1使用Remembered Sets来跟踪跨Region的引用关系。
                        </p>
                    </div>
                </div>
                
                <!-- Phase 3 -->
                <div class="relative mb-10 timeline-item">
                    <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                        <div class="flex items-center mb-3">
                            <span class="flex items-center justify-center w-10 h-10 rounded-full bg-purple-100 text-purple-700 font-bold mr-4">3</span>
                            <h4 class="text-xl font-semibold text-gray-800">最终标记 (Final Mark)</h4>
                            <span class="ml-auto px-3 py-1 bg-red-100 text-red-800 text-sm font-medium rounded-full">STW</span>
                        </div>
                        <p class="text-gray-600 pl-14">
                            处理SATB缓冲区中的引用变更，完成标记的最后一步。需要短暂暂停应用线程(STW)来处理在并发标记阶段可能遗漏的对象引用变化。
                        </p>
                    </div>
                </div>
                
                <!-- Phase 4 -->
                <div class="relative timeline-item">
                    <div class="bg-white p-6 rounded-xl shadow-md card-hover">
                        <div class="flex items-center mb-3">
                            <span class="flex items-center justify-center w-10 h-10 rounded-full bg-pink-100 text-pink-700 font-bold mr-4">4</span>
                            <h4 class="text-xl font-semibold text-gray-800">筛选和清理 (Cleanup)</h4>
                            <span class="ml-auto px-3 py-1 bg-yellow-100 text-yellow-800 text-sm font-medium rounded-full">部分STW</span>
                        </div>
                        <p class="text-gray-600 pl-14">
                            统计各Region的存活对象和回收价值，根据用户设置的<code class="bg-gray-100 px-1 py-0.5 rounded">-XX:MaxGCPauseMillis</code>目标，选择最有回收价值的Region进行回收。部分操作需要STW，部分可以并发执行。
                        </p>
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 card-hover">
                <h3 class="text-2xl font-semibold mb-6 text-gray-800 flex items-center">
                    <i class="fas fa-chart-line mr-3 text-indigo-500"></i> 增量式垃圾回收
                </h3>
                <div class="grid md:grid-cols-2 gap-8 items-center">
                    <div>
                        <p class="text-gray-600 mb-4 drop-cap">
                            G1通过分阶段、增量式的方式回收内存，将原本一次大规模STW停顿分解为多次小停顿。这种"分而治之"的策略使得停顿时间更加可控，特别适合需要低延迟的大堆应用。
                        </p>
                        <p class="text-gray-600">
                            回收过程中，G1会根据Region的回收价值(垃圾量/回收时间)进行排序，优先回收那些垃圾比例高的Region。通过这种智能选择，G1能够在有限的时间内最大化回收内存空间，实现用户设定的停顿时间目标。
                        </p>
                    </div>
                    <div class="mermaid">
                        pie
                            title G1回收决策因素
                            "Region中垃圾占比" : 45
                            "回收所需时间" : 30
                            "跨Region引用复杂度" : 15
                            "其他因素" : 10
                    </div>
                </div>
            </div>
        </section>

        <!-- Advantages Section -->
        <section class="mb-16">
            <h2 class="serif text-3xl font-bold mb-8 text-gray-800 border-b pb-4 flex items-center">
                <i class="fas fa-medal mr-3 text-indigo-600"></i> G1垃圾回收器的核心优势
            </h2>
            
            <div class="grid md:grid-cols-2 gap-8 mb-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 card-hover">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-sliders-h mr-3 text-blue-500"></i> 可预测的停顿时间
                    </h3>
                    <p class="text-gray-600">
                        通过<code class="bg-gray-100 px-2 py-1 rounded">-XX:MaxGCPauseMillis</code>参数，用户可以设置期望的最大停顿时间(默认200ms)。G1会尝试在此时间内完成垃圾回收，通过智能选择回收区域和增量式回收来实现这一目标。
                    </p>
                    <div class="mt-4 flex items-center text-sm text-gray-500">
                        <i class="fas fa-info-circle mr-2"></i>
                        注意：这是目标时间，并非严格保证，实际停顿时间可能受多种因素影响。
                    </div>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 card-hover">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-chess-board mr-3 text-purple-500"></i> 区域化内存管理
                    </h3>
                    <p class="text-gray-600">
                        Region-based的内存布局避免了传统分代模型的碎片化问题。每个Region独立进行回收和分配，老年代不再需要连续空间，大大提高了内存使用效率和灵活性。
                    </p>
                    <div class="mt-4 flex items-center text-sm text-gray-500">
                        <i class="fas fa-lightbulb mr-2"></i>
                        Humongous区域专门存储大对象(超过Region 50%)，减少大对象对内存布局的影响。
                    </div>
                </div>
            </div>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 card-hover">
                <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                    <i class="fas fa-robot mr-3 text-green-500"></i> 自适应优化机制
                </h3>
                <div class="grid md:grid-cols-2 gap-6">
                    <div>
                        <h4 class="font-medium text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-memory mr-2"></i> 动态调整年轻代大小
                        </h4>
                        <p class="text-gray-600 text-sm">
                            G1会根据应用行为和历史GC数据动态调整年轻代大小，在满足停顿时间目标的前提下最大化吞吐量。
                        </p>
                    </div>
                    <div>
                        <h4 class="font-medium text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-tachometer-alt mr-2"></i> 启发式预测模型
                        </h4>
                        <p class="text-gray-600 text-sm">
                            基于历史GC性能数据建立预测模型，智能选择回收区域数量和回收策略，以最优方式达到用户设定的目标。
                        </p>
                    </div>
                    <div>
                        <h4 class="font-medium text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-exchange-alt mr-2"></i> 并行与并发结合
                        </h4>
                        <p class="text-gray-600 text-sm">
                            充分利用多核CPU优势，将可以并行的任务(如标记)并行化，必须STW的任务尽量缩短时间。
                        </p>
                    </div>
                    <div>
                        <h4 class="font-medium text-gray-700 mb-2 flex items-center">
                            <i class="fas fa-clipboard-list mr-2"></i> Remembered Sets优化
                        </h4>
                        <p class="text-gray-600 text-sm">
                            高效维护跨Region引用关系，减少扫描范围，只处理真正需要检查的引用关系。
                        </p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Configuration Section -->
        <section class="mb-16">
            <h2 class="serif text-3xl font-bold mb-8 text-gray-800 border-b pb-4 flex items-center">
                <i class="fas fa-cog mr-3 text-indigo-600"></i> G1垃圾回收器配置指南
            </h2>
            
            <div class="bg-white rounded-xl shadow-md overflow-hidden mb-8 card-hover">
                <div class="p-8">
                    <h3 class="text-2xl font-semibold mb-6 text-gray-800 flex items-center">
                        <i class="fas fa-terminal mr-3 text-indigo-500"></i> 基础配置参数
                    </h3>
                    
                    <div class="overflow-x-auto">
                        <table class="min-w-full divide-y divide-gray-200">
                            <thead class="bg-gray-50">
                                <tr>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">参数</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">默认值</th>
                                    <th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">说明</th>
                                </tr>
                            </thead>
                            <tbody class="bg-white divide-y divide-gray-200">
                                <tr class="hover:bg-gray-50">
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900"><code>-XX:+UseG1GC</code></td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">N/A</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">启用G1垃圾回收器</td>
                                </tr>
                                <tr class="hover:bg-gray-50">
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900"><code>-XX:MaxGCPauseMillis</code></td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">200ms</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">目标最大停顿时间</td>
                                </tr>
                                <tr class="hover:bg-gray-50">
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900"><code>-XX:G1HeapRegionSize</code></td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">堆大小/2048</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">设置Region大小(1MB-32MB)</td>
                                </tr>
                                <tr class="hover:bg-gray-50">
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900"><code>-XX:InitiatingHeapOccupancyPercent</code></td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">45%</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">触发并发标记周期的堆占用阈值</td>
                                </tr>
                                <tr class="hover:bg-gray-50">
                                    <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900"><code>-XX:G1ReservePercent</code></td>
                                    <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">10%</td>
                                    <td class="px-6 py-4 text-sm text-gray-500">保留内存比例，防止to-space溢出</td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 card-hover">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-flask mr-3 text-blue-500"></i> 调优建议
                    </h3>
                    <ul class="space-y-3 text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>对于大堆应用(>6GB)，建议设置<code class="bg-gray-100 px-1 py-0.5 rounded">-XX:G1HeapRegionSize</code>为8MB或更大</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>合理设置<code class="bg-gray-100 px-1 py-0.5 rounded">-XX:MaxGCPauseMillis</code>，过小会导致频繁GC，过大则失去意义</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>监控<code class="bg-gray-100 px-1 py-0.5 rounded">To-space exhausted</code>情况，适当增加<code class="bg-gray-100 px-1 py-0.5 rounded">-XX:G1ReservePercent</code></span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>避免设置<code class="bg-gray-100 px-1 py-0.5 rounded">-Xmn</code>明确年轻代大小，让G1自动优化</span>
                        </li>
                    </ul>
                </div>
                
                <div class="bg-white rounded-xl shadow-md overflow-hidden p-8 card-hover">
                    <h3 class="text-xl font-semibold mb-4 text-gray-800 flex items-center">
                        <i class="fas fa-chart-bar mr-3 text-purple-500"></i> 监控与分析
                    </h3>
                    <ul class="space-y-3 text-gray-600">
                        <li class="flex items-start">
                            <i class="fas fa-desktop text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>使用<code class="bg-gray-100 px-1 py-0.5 rounded">-Xlog:gc*</code>开启详细GC日志</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-chart-pie text-purple-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>通过<code class="bg-gray-100 px-1 py-0.5 rounded">jstat -gcutil</code>实时监控GC状态</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-search text-green-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>使用GC日志分析工具(如GCViewer、GCEasy)分析性能瓶颈</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-tools text-yellow-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>关注<code class="bg-gray-100 px-1 py-0.5 rounded">Evacuation Failure</code>和<code class="bg-gray-100 px-1 py-0.5 rounded">To-space overflow</code>等关键指标</span>
                        </li>
                    </ul>
                </div>
            </div>
        </section>

        <!-- Summary Section -->
        <section class="mb-16">
            <div class="bg-indigo-50 rounded-xl shadow-md overflow-hidden p-8 card-hover">
                <h2 class="serif text-2xl font-bold mb-6 text-indigo-800">
                    <i class="fas fa-gem mr-3"></i> G1垃圾回收器适用场景
                </h2>
                <div class="grid md:grid-cols-2 gap-8">
                    <div>
                        <h3 class="text-lg font-semibold mb-3 text-indigo-700 flex items-center">
                            <i class="fas fa-thumbs-up mr-2"></i> 推荐使用场景
                        </h3>
                        <ul class="space-y-2 text-indigo-900">
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>堆内存较大(6GB以上)的应用</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>对停顿时间敏感的应用(如交易系统、实时系统)</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>应用会产生大量内存碎片的情况</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-check text-green-500 mt-1 mr-2"></i>
                                <span>需要平衡吞吐量和延迟的应用</span>
                            </li>
                        </ul>
                    </div>
                    <div>
                        <h3 class="text-lg font-semibold mb-3 text-indigo-700 flex items-center">
                            <i class="fas fa-thumbs-down mr-2"></i> 不推荐场景
                        </h3>
                        <ul class="space-y-2 text-indigo-900">
                            <li class="flex items-start">
                                <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                                <span>非常小的堆(<1GB)，此时Serial或Parallel可能更高效</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                                <span>对吞吐量要求极高但可以容忍较长停顿的应用</span>
                            </li>
                            <li class="flex items-start">
                                <i class="fas fa-times text-red-500 mt-1 mr-2"></i>
                                <span>需要极低延迟(亚毫秒级)的实时系统</span>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-8">
        <div class="container mx-auto max-w-5xl px-4">
            <div class="flex flex-col md:flex-row justify-between items-center">
                <div class="mb-4 md:mb-0">
                    <h3 class="text-xl font-medium text-white mb-2">技术小馆</h3>
                    <p class="text-gray-400">深入技术细节，探索底层原理</p>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="text-gray-300 hover:text-white transition duration-300 flex items-center">
                        <i class="fas fa-external-link-alt mr-2"></i> 访问技术小馆语雀主页
                    </a>
                </div>
            </div>
            <div class="mt-8 pt-6 border-t border-gray-800 text-center text-sm text-gray-400">
                &copy; 2023 技术小馆. 保留所有权利.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            },
            gantt: {
                axisFormat: '%m/%d/%Y'
            }
        });
    </script>
</body>
</html>